<?php
	// Quảng cáo - Phần xử lý
	class quangcaodb
	{
	 	public function Them($TenKhachHang = "", 
	 						 $HinhAnh = "", 
	 						 $DiaChi = "",
	 						 $XuatBan = 0)
		{
			$sql = "insert into quangcao(TenKhachHang, HinhAnh, DiaChi,XuatBan) 
					values(".dataservice::QuoteSmart($TenKhachHang).",
						   ".dataservice::QuoteSmart($HinhAnh).", 
						   ".dataservice::QuoteSmart($DiaChi).",
						   ".dataservice::QuoteSmart($XuatBan).")";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhatXuatBan($MaQuangCao = 0, $XuatBan = 0)
		{
			$sql = "update quangcao 
					set 
						XuatBan = ".dataservice::QuoteSmart($XuatBan)." 
					where 
						MaQuangCao = ".dataservice::QuoteSmart($MaQuangCao);		
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaQuangCao = 0, 
								$TenKhachHang = '', 
								$HinhAnh = '', 
								$DiaChi = '')
		{
			$sql = "update quangcao 
					set TenKhachHang = ".dataservice::QuoteSmart($TenKhachHang).", 
						HinhAnh = ".dataservice::QuoteSmart($HinhAnh).", 
						DiaChi = ".dataservice::QuoteSmart($DiaChi)." 
					where 
						MaQuangCao = ".dataservice::QuoteSmart($MaQuangCao);
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
	  	public function LayDanhSach($MaQuangCao = 0,
	  								$TenKhachHang = "",
	  								$DiaChi = "",
	  								$XuatBan = 0)
		{
			$sql = "select * from quangcao where (1)";
			
			if($MaQuangCao > 0)
				$sql .= " AND MaQuangCao = $MaQuangCao";
				
			if($TenKhachHang != "")
				$sql .= " AND TenKhachHang = '$TenKhachHang'";
				
			if($DiaChi != "")
				$sql .= " AND DiaChi = '$DiaChi'";
				
			if($XuatBan > 0)
				$sql .= " AND XuatBan = $XuatBan";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaQuangCao = 0)
		{
			$sql = 'delete from quangcao where (1)';
			
			if ($MaQuangCao > 0)
				$sql .= ' and MaQuangCao = '.dataservice::QuoteSmart($MaQuangCao);
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM quangcao";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	}
?>